package Q2;

import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[] arr = new int[n];

        //大根堆
        PriorityQueue<Map.Entry<Integer, Integer>> queue = new PriorityQueue<>(new Comparator<Map.Entry<Integer, Integer>>() {
            @Override
            public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                return o2.getValue() - o1.getValue();
            }
        });
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
            map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
        }

        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            queue.offer(entry);
        }

        int max = queue.peek().getKey();

        while (m > 0) {
            m--;
            Map.Entry<Integer, Integer> entry = queue.poll();
            int num1 = entry.getValue() / 2;
            int num2 = entry.getValue() - num1;
            entry.setValue(num1);
            queue.offer(entry);
            entry.setValue(num2);
            queue.offer(entry);

            if (queue.peek().getKey() != max) {
                System.out.println(queue.peek().getValue());
                return;
            }
        }

        if (queue.peek().getKey() == max) {
            System.out.println(-1);
        } else {
            System.out.println(queue.peek().getValue());
        }

    }
}
